// DatoNotatForm.cpp : implementation file
//

#include "stdafx.h"
#include "EBASApp.h"
#include "DatoNotatForm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DatoNotatForm

IMPLEMENT_DYNCREATE(CDatoNotatForm, CFormView)

CDatoNotatForm::CDatoNotatForm()
	: CFormView(CDatoNotatForm::IDD)
{
	//{{AFX_DATA_INIT(DatoNotatForm)
	m_cpr = _T("");
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	CEBASAppApp::g_nCurrentView = DATONOTAT;

	m_pDatoNotat = NULL;
	m_pDatoNotatListe = NULL;
}

CDatoNotatForm::~CDatoNotatForm()
{
	if (m_pDatoNotat)
		m_pDatoNotat->Destroy();
	if (m_pDatoNotatListe)
		m_pDatoNotatListe->Destroy();
}

void CDatoNotatForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DatoNotatForm)
	DDX_Text(pDX, IDC_EDIT_DATONOTAT_CPR, m_cpr);
	DDX_Control(pDX, IDC_TAB_DATONOTAT, m_tabs);
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDatoNotatForm, CFormView)
	//{{AFX_MSG_MAP(CDatoNotatForm)
//	ON_BN_CLICKED(IDC_BUTTON_DATONOTAT_HENT, OnButtonDatonotatHent)
//	ON_BN_CLICKED(IDC_TAB_DATONOTAT, OnClickTabCtrl)
	ON_NOTIFY(NM_CLICK, IDC_TAB_DATONOTAT, OnClickTabCtrl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DatoNotatForm diagnostics

#ifdef _DEBUG
void CDatoNotatForm::AssertValid() const
{
	CFormView::AssertValid();
}

void CDatoNotatForm::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// DatoNotatForm message handlers

void CDatoNotatForm::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	EBASDLLLib::IStuderendePtr pStuderende;
	pStuderende = CEBASAppApp.gpEbasSession->AktivStuderende;
	if (NULL != pStuderende) {
		m_cpr = (char*)pStuderende->CPRNr;
	}

	EBASDLLLib::IDatoNotatPtr pNotat = NULL;
	pNotat = (CEBASAppApp::gpEbasSession)->PlaceHolder; 
	if (NULL != pNotat) {			
		m_pDatoNotat->m_dato = (char*)pNotat->Dato;		
		m_pDatoNotat->m_emne = (char*)pNotat->Emne;

	}

	m_tabs.InsertItem(0, "DatoNotat");
	m_tabs.InsertItem(1, "DatoNotatListe");
	m_tabs.SetCurSel(0);

	CStatic * pStatic = (CStatic *)GetDlgItem(IDC_STATIC_INVISIBLE);
	
	WINDOWPLACEMENT * pWplacement = NULL;
	pWplacement = (WINDOWPLACEMENT *)malloc(sizeof(WINDOWPLACEMENT));
	pStatic->GetWindowPlacement(pWplacement);

	m_pDatoNotat = new CDatoNotatPropertyPage;
	m_pDatoNotat->Create();
	m_pDatoNotat->SetWindowPlacement(pWplacement);

	m_pDatoNotatListe = new CDatoNotatListePropertyPage;
	m_pDatoNotatListe->Create();
	m_pDatoNotatListe->SetWindowPlacement(pWplacement);
	m_pDatoNotatListe->ShowWindow(SW_HIDE);

	if (pWplacement)
		free(pWplacement);

	UpdateData(FALSE);
}

void CDatoNotatForm::OnClickTabCtrl(NMHDR * pNotifyStruct, LRESULT * pResult)
{
	*pResult = 0;
	int nCurTab = m_tabs.GetCurSel();
	switch (nCurTab)
	{
		case 0:
			m_pDatoNotatListe->ShowWindow(SW_HIDE);
			m_pDatoNotat->ShowWindow(SW_SHOW);
			break;
		case 1:
			m_pDatoNotat->ShowWindow(SW_HIDE);	
			m_pDatoNotatListe->ShowWindow(SW_SHOW);
	}
}
